//
// Created by xili on 2024/8/25 17:36.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    vector<int> getSumAbsoluteDifferences(vector<int>& nums) {
        int n = nums.size(),leftsum = 0,rightsum = accumulate(nums.begin(),nums.end(),0);
        vector<int> result(n);
        for(int i = 0; i < n ; i++){
            rightsum -= nums[i];
            result[i] = i * nums[i] - leftsum + rightsum - (n - i - 1) * nums[i];
            leftsum += nums[i];
        }
        return result;
    }
};